﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ImTag.Silverlight
{
    public enum TagMode { Search, DeSearch, Remove }
    public partial class Tag : UserControl
    {
        public Tag()
        {
            InitializeComponent();
            this.MouseLeftButtonDown += (source, ev) =>
            {
                var bar = MainPage.Current.SearchBar;
                if ((Keyboard.Modifiers & ModifierKeys.Control) == 0)
                    bar.SearchTags = new string[] { this.TagText };
                else
                {
                    if (bar.SearchTags.Contains(this.TagText))
                        bar.SearchTags = bar.SearchTags.Where(s => s != this.TagText);
                    else
                        bar.SearchTags = bar.SearchTags.Concat(new string[] { this.TagText });
                }
                bar.PerformSearch();
            };
        }

        public string TagText
        {
            get { return this.TextBlock.Text; }
            set { this.TextBlock.Text = value; }
        }
        private TagMode tagMode;

        public TagMode TagMode
        {
            get { return tagMode; }
            set 
            {
                this.tagMode = value;
                if (value == Silverlight.TagMode.Search)
                {
                    this.Background.Background = new SolidColorBrush(Colors.Blue);
                }
                else if (value == Silverlight.TagMode.Remove)
                {
                    this.Background.Background = new SolidColorBrush(Colors.Red);
                }
            }
        }
    }
}
